package io.itit.ecp.admin.provide.action.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import icu.mhb.mybatisplus.plugln.core.JoinLambdaWrapper;
import io.itit.ecp.admin.provide.action.req.EnergyDataQueryReq;
import io.itit.ecp.admin.provide.action.resp.EnergyDataResp;
import io.itit.ecp.admin.provide.filter.IEnergyDataFilter;
import io.itit.ecp.admin.provide.helper.SceneHelper;
import io.itit.ecp.admin.server.entity.EnergyDataEntity;
import io.itit.grass.common.provide.action.req.BaseBatchIdReq;
import io.itit.grass.common.provide.action.req.BaseIdReq;
import io.itit.grass.common.provide.action.resp.ResultResp;
import io.itit.grass.common.provide.action.validation.IExport;
import io.itit.grass.common.provide.action.validation.IQueryPage;
import io.itit.grass.common.provide.action.validation.IRequired;
import io.itit.grass.estelle.starter.core.ExcelXSSFUtil;
import io.itit.grass.estelle.starter.util.JsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运行模式数据
 */
@Api(tags = "运行模式数据")
@RestController
@RequestMapping("/ecp-admin/runningModeData")
public class RunningModeDataController {

    @ApiOperation("分页查询")
    @PostMapping("queryPage")
    @RequiresPermissions("ecp-admin:runningModeData:search")
    public ResultResp<IPage<EnergyDataResp>> queryPage(@RequestBody @Validated(IQueryPage.class) EnergyDataQueryReq req) {
        return ResultResp.success(new Page<>());
    }

    @ApiOperation("删除(根据Id删)")
    @PostMapping("deleteById")
    @RequiresPermissions("ecp-admin:runningModeData:deleteById")
    public ResultResp<Boolean> deleteById(@RequestBody @Validated({IRequired.class}) BaseIdReq req) {
        return ResultResp.success(true);
    }

    @ApiOperation("批量删除")
    @PostMapping("batchDelete")
    @RequiresPermissions("ecp-admin:runningModeData:batchDelete")
    public ResultResp<Boolean> batchDelete(@RequestBody @Validated({IRequired.class}) BaseBatchIdReq req) {
        return ResultResp.success(true);
    }

    @ApiOperation("导出")
    @PostMapping("export")
    @RequiresPermissions("ecp-admin:runningModeData:export")
    public void export(@RequestBody @Validated(IExport.class) EnergyDataQueryReq req, HttpServletResponse response) {
        List<EnergyDataResp> respList = SceneHelper.i().setSceneInfo(buildQW(req).joinList(EnergyDataResp.class));
        ExcelXSSFUtil.export("RunningModeDataExport", JsonUtil.toJson(respList, new IEnergyDataFilter.EnergyDataExtExportFilter()), response);
    }

    private static JoinLambdaWrapper<EnergyDataEntity> buildQW(EnergyDataQueryReq req) {
        return null;
    }
}
